<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="beans.UserBean,beans.MessageBean,java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Messages - <%
	UserBean currentUser = (UserBean) session
			.getAttribute("currentSessionUser");
	out.print(currentUser.getName());
%></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
	padding-top: 60px;
	padding-bottom: 40px;
}

#sexyline {
	margin: 25px 0;
	height: 1px;
	background: #eeeee;
	background: -webkit-gradient(linear, 0 0, 100% 0, from(white), to(white),
		color-stop(50%, grey) );
}
​
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!--Custom JS scripts-->

<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144"
	href="ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
	href="ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
	href="ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed"
	href="ico/apple-touch-icon-57-precomposed.png">
</head>

<body>

	<div class="navbar navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<a class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse"> <span class="icon-bar"></span> <span
					class="icon-bar"></span> <span class="icon-bar"></span>
				</a> <a class="brand" href="#">drop.in</a>
				<div class="nav-collapse">
					<ul class="nav">
						<li class="active"><a href="#">Home</a></li>
						<li><a href="#about">About</a></li>
						<li><a href="#contact">Contact</a></li>
					</ul>
				</div>
				<!--/.nav-collapse -->
			</div>
		</div>
	</div>

	<div class="container">

		<!-- Main hero unit for a primary marketing message or call to action -->
		<div class="hero-unit" style="padding: 10px 10px 10px 10px;">
			<div style="text-align: center;">
				<h2>Your Messages</h2>
			</div>
		</div>
		<div class="row">
			<div class="span12">
				<ul class="nav nav-tabs">
					<%
						String currentboxx = (String) session.getAttribute("currentbox");
						if (currentboxx.equals("received")) {
							out.print("<li class='active'><a href='http://localhost:8080/dropin/MessagesServlet?id="
									+ currentUser.getEmail()
									+ "&box=received&page=1'>Inbox</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
									+ currentUser.getEmail()
									+ "&box=sent&page=1'>Sentbox</a></li>");
						} else {
							out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
									+ currentUser.getEmail()
									+ "&box=received&page=1'>Inbox</a></li>");
							out.print("<li class='active'><a href='http://localhost:8080/dropin/MessagesServlet?id="
									+ currentUser.getEmail()
									+ "&box=sent&page=1'>Sentbox</a></li>");
						}
					%>
				</ul>
				<%
					Integer pg = (Integer) session.getAttribute("currentpagenumber");
					ArrayList<MessageBean> messages = (ArrayList<MessageBean>) session
							.getAttribute("displaymessages");
					if ((messages.isEmpty()) || ((pg - 1) * 10 >= messages.size())) {
						out.print("<blockquote style='text-align: center; height: 100px; font-size: 18px; font-style: italic; padding-top: 70px;'>There are no messages to display!</blockquote>");
					} else {
						if (currentboxx.equals("received")) {
							for (int i = (pg - 1) * 10; i < (pg * 10); i++) {
								if (i < messages.size()) {
									out.print("<blockquote>"
											+ messages.get(i).getBody()
											+ "<small>Sent by <a href='http://localhost:8080/dropin/VisitServlet?visitid="
											+ messages.get(i).getSender() + "'>");
									out.print(messages.get(i).getSenderName());
									out.print("</a> on ");
									String msgdate = (messages.get(i).getStamp()
											.toString());
									out.print(msgdate.substring(0, 16) + "  ");
									if (messages.get(i).isPrivate()) {
										out.print("<span class='label label-info'>Private Message</span>");
									}
									out.print(" | <a href='http://localhost:8080/dropin/ReplyServlet?reply=" + messages.get(i).getCommentID() + "&to=" + messages.get(i).getSender() + "'><i class='icon-share-alt'></i> Reply</a> | ");
									if (messages.get(i).getReplyTo() != 1) {
										out.print("<a href='http://localhost:8080/dropin/ConversationServlet?id=" + messages.get(i).getCommentID() + "&partner=" + messages.get(i).getReceiverName() + "'><i class='icon-list-alt'></i> Show Conversation | </a>");
									}
									out.print("<a href='http://localhost:8080/dropin/DeleteMessageServlet?id=" + messages.get(i).getCommentID() + "&box=received'><i class='icon-trash'></i> Delete</a>");
									out.print("</small></blockquote>");
								}
							}
						} else {
							for (int i = (pg - 1) * 10; i < (pg * 10); i++) {
								if (i < messages.size()) {
									out.print("<blockquote>"
											+ messages.get(i).getBody()
											+ "<small>Sent to <a href='http://localhost:8080/dropin/VisitServlet?visitid="
											+ messages.get(i).getReceiver() + "'>");
									out.print(messages.get(i).getReceiverName());
									out.print("</a> on ");
									String msgdate = (messages.get(i).getStamp()
											.toString());
									out.print(msgdate.substring(0, 16) + "  ");
									if (messages.get(i).isPrivate()) {
										out.print("<span class='label label-info'>Private Message</span>");
									}
									//out.print(" | <a href='http://localhost:8080/dropin/ReplyServlet?reply=" + messages.get(i).getCommentID() + "&to=" + messages.get(i).getReceiver() + "'>Reply</a> | ");
									if (messages.get(i).getReplyTo() != 1) {
										out.print("<a href='http://localhost:8080/dropin/ConversationServlet?id=" + messages.get(i).getCommentID() + "&partner=" + messages.get(i).getReceiverName() + "'>| <i class='icon-list-alt'></i> Show Conversation | </a>");
									}
									out.print("<a href='http://localhost:8080/dropin/DeleteMessageServlet?id=" + messages.get(i).getCommentID() + "&box=sent'><i class='icon-trash'></i> Delete</a>");
									out.print("</small></blockquote>");
								}
							}
						}
					}
				%>

				<div class="pagination" align="center">
					<ul>
						<%
							//Integer pg = (Integer)session.getAttribute("currentpagenumber");
							if (pg == 1) {
								out.print("<li class='disabled'><a href='http://localhost:8080/dropin/messages.jsp' class='disabled'>Prev</a></li>");
							} else {
								out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg - 1) + "'>Prev</a></li>");
							}
						%>
						<%
							if (pg == 1) {
								out.print("<li class='active'><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page=1'>1</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page=2'>2</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page=3'>3</a></li>");
							} else {
								out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg - 1)
										+ "'>"
										+ Integer.toString(pg - 1) + "</a></li>");
								out.print("<li class='active'><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg)
										+ "' class='active'>"
										+ Integer.toString(pg) + "</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg + 1)
										+ "'>"
										+ Integer.toString(pg + 1) + "</a></li>");
							}
						%>
						<%
							//Integer pg = (Integer)session.getAttribute("currentpagenumber");
							if (pg >= (messages.size() / 10) + 1) {
								out.print("<li class='disabled'><a href='http://localhost:8080/dropin/messages.jsp' class='disabled'>Next</a></li>");
							} else {
								out.print("<li><a href='http://localhost:8080/dropin/MessagesServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg + 1) + "'>Next</a></li>");
							}
						%>
					</ul>
				</div>
			</div>
			</div>
			</div>
			<footer>
        		<p style="text-align: center; margin-top: 50px; color: grey;">&copy; PiP 2012</p>
			</footer>

		</div>
		<!-- /container -->

		<!-- Le javascript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
		<script
			src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
		<script src="js/bootstrap.js"></script>
		<script src="js/bootstrap-alert.js"></script>
		<script src="js/bootstrap-modal.js"></script>
		<script src="js/bootstrap-dropdown.js"></script>
		<script src="js/bootstrap-scrollspy.js"></script>
		<script src="js/bootstrap-tab.js"></script>
		<script src="js/bootstrap-tooltip.js"></script>
		<script src="js/bootstrap-popover.js"></script>
		<script src="js/bootstrap-button.js"></script>
		<script src="js/bootstrap-collapse.js"></script>
		<script src="js/bootstrap-carousel.js"></script>
		<script src="js/bootstrap-typeahead.js"></script>
</body>
</html>
